<template>
    <div id="briefCenter">
        <div class="brief_center_content">
            <h3 class="brief_center_title">简报模板</h3>
            <el-button class="createBrief" @click="createTemplate">新建模板</el-button>
            <ul class="brief_center_template">
                <li v-for="item in templateList" :key="item.id">
                    <div v-if="item.isDefault == 'Y'" class="defaultIdentification">
                        <span>默认</span>
                    </div>
                    <h4 @click="detailTemplate(item.id)">{{item.templateName}}</h4>
                    <span :class="item.isDefault=='Y'? 'defaultTemplate':'template'"></span>
                    <div class="btnGroup">
                        <el-button v-if="item.isDefault=='Y'" class="defaultBtn">设为默认</el-button>
                        <el-button v-else class="setdefaultBtn" @click="setDefault(item.id)">设为默认</el-button>
                        <el-button class="editBtn">编辑</el-button>
                        <el-button class="deleteBtn" @click="delTemplate(item.id)">删除</el-button>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</template>
<script>
import '../../assets/css/briefCenter.css'
export default {
    data(){
        return{
            templateList:[
                // {
                //     bulletinSummarySelect: 1,
                //     createTime: "2020-07-23 01:00:15",
                //     emotionSelect: 1,
                //     id: 1,
                //     isDefault: "Y",
                //     isSystem: 0,
                //     mainOpinionSelect: 1,
                //     mainOpinionSort: null,
                //     outsideSelect: 1,
                //     regionSelect: 1,
                //     siteSelect: 1,
                //     sourceSelect: 1,
                //     suggestSelect: 1,
                //     surveySummarySelect: 1,
                //     templateName: "系统模板",
                //     titleSelect: 1,
                //     trendSelect: 1,
                //     userId: 2
                // }
            ]
        }
    },
    created(){
        this.templateListData()
    },
    methods:{
        detailTemplate(id){
            let path = '/createTemplate/'+ id;
            this.$router.push({path: path});
        },
        templateListData(){
            this.$Api.templateList().then(res => {
                console.log(res);
                if(res.code == '200'){
                  this.templateList = res.data;
                }
            })
        },
        delTemplate(id){
            let param = id
            this.$Api.templateDel(param).then(res => {
                console.log(res);
                if(res.code == '200'){
                  this.templateListData()
                }
            })
        },
        createTemplate(){
            this.$router.push({path: '/createTemplate/newTemplate'})
        },
        setDefault(listId){
            let param = listId
            this.$Api.templateDefault(param).then(res => {
                console.log(res);
                if(res.code == '200'){
                  this.templateListData()
                }
            })
        }
    }
}
</script>